local cjson = require "cjson"
-- 多余的空白并不影响json解析
local text = [[
{       
	"hostname" :"asay.pub","ip":"::ffff:219.156.100.21","baseUrl":"","fresh":false,
	"originalUrl":"/info","params":{},"path":"/info","protocol":"http","query":{},
	"name":"哈哈"
}
]]

-- 将字符串解析为对象
local res = cjson.decode(text)
print(not res.fresh)
print(res.hostname)
print(res["name"])
print()


-- 在对象中添加一些字段
res.age = 100 
res.childs = {1,2,3}

-- 将对象解析为字符串
local text = cjson.encode(res)
print(text)
print()


local response = [[{"name":"haha","age":12,"childs":["xiao1","xiao2",97,63]}]]
local cjson = require "cjson"
local res = cjson.decode(response)
print(res.name)
print(res.age)
print(res.childs[3])

